package utils

import (
	"math/rand"
	"strconv"
	"time"
)

var runes = []byte{
	'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
	'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
	'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
}

// RandString 随机字符串
func RandString(n int) (res string) {
	length := len(runes)
	v := make([]byte, n)
	for i := 0; i < n; i++ {
		v[i] = runes[rand.Intn(length)]
	}
	res = string(v)
	return
}

func ToTime(str string) (val time.Time) {
	v, _ := strconv.ParseInt(str, 10, 64)
	return time.Unix(v, 0)
}

func ToInt(str string) (val int) {
	val, _ = strconv.Atoi(str)
	return
}

func ToInt64(str string) (val int64) {
	val, _ = strconv.ParseInt(str, 10, 64)
	return
}

func ToBool(str string) (val bool) {
	val, _ = strconv.ParseBool(str)
	return
}
